const fs = require('fs');
const path = require('path');
const sqlite3 = require('../server/node_modules/sqlite3').verbose();

// 检查数据库中user_lesson_progress表的time_spent字段
const dbPath = path.join(__dirname, '../resources/db/db.database');
console.log('Database path:', dbPath);

const db = new sqlite3.Database(dbPath);

console.log('\n=== User Lesson Progress Data ===');
db.serialize(() => {
  db.all("SELECT * FROM user_lesson_progress", (err, rows) => {
    if (err) {
      console.error('Error:', err);
    } else {
      console.log('User lesson progress rows:');
      rows.forEach(row => {
        console.log(`ID: ${row.id}, User ID: ${row.user_id}, Lesson ID: ${row.lesson_id}, Course ID: ${row.course_id}, Time Spent: ${row.time_spent}, Completion: ${row.completion_percentage}%`);
      });
    }
    
    console.log('\n=== Checking if time_spent is being updated ===');
    // 检查是否有任何非零的time_spent值
    db.get("SELECT COUNT(*) as count FROM user_lesson_progress WHERE time_spent > 0", (err, row) => {
      if (err) {
        console.error('Error:', err);
      } else {
        console.log(`Number of records with time_spent > 0: ${row.count}`);
      }
      
      db.close();
    });
  });
});